#pragma once
#include "base/http/http_protocol_interface_define.h"
namespace app_sdk {
/** @class SDK_PRO
 * @brief app_sdk 协议定义
 * @copyright (c) 2018, NetEase Inc. All rights reserved
 * @date 2018/4/26
 */
class SDK_PRO {
private:
    /** @class ResponseBase
     * @brief app_sdk 应答基类
     * @copyright (c) 2018, NetEase Inc. All rights reserved
     * @date 2018/4/26
     */
    class ResponseBase : public IHttpResponse {
    public:
        ResponseBase() = default;
        virtual ~ResponseBase() = default;
        // 解析应答数据
        virtual void Parse(const std::string& response) override;
        // 获取原始应答数据
        std::string GetReplyContent() const;
        // 获取协议定义的业务返回码
        virtual int32_t GetProtocolReplyCode() const;

    protected:
        virtual void OnParse(const std::string& response);
        void SetProtocolReplyCode(int code);

    private:
        std::string reply_content_;  // 应答原始数据
        int32_t pro_reply_code_;     // 业务返回码
    };
    /** @class RequestBase
     * @brief app_sdk 请求基类
     * @copyright (c) 2018, NetEase Inc. All rights reserved
     * @date 2018/4/26
     */
    class RequestBase : public IHttpRequest {
    public:
        RequestBase() = default;
        virtual ~RequestBase() = default;
        virtual std::string GetAPIURL() const override;
        virtual bool UsePostMethod() const override;
        virtual void GetRequestContent(std::string& content) const override;
        virtual void GetRequestHead(std::map<std::string, std::string>& heads) override;

    protected:
        virtual bool IsUsePostMethod() const;
        virtual void OnGetRequestContent(std::string& content) const;
        // 获取请求的连接地址，可以直接返回，或者由OnGetHost与OnGetApi拼起来，可以参考示例程序
        virtual std::string OnGetAPIURL() const;
        virtual std::string OnGetHost() const;
        virtual std::string OnGetAPI() const;
        virtual void OnGetRequestHead(std::map<std::string, std::string>& heads) const;

    private:
        mutable std::string app_url_;
    };

    // APP更新请求应答
    class AppUpdateRequest : public RequestBase {
    public:
        AppUpdateRequest(std::string platform, std::string token);
    protected:
        virtual std::string OnGetHost() const override;
        virtual std::string OnGetAPI() const override;
        virtual void OnGetRequestHead(std::map<std::string, std::string>& heads) const override;
        virtual void OnGetRequestContent(std::string& content) const override;
    public:
        std::string platform_;
        std::string token_;
    };
    class AppUpdateResponse : public ResponseBase {
    protected:
        virtual void OnParse(const std::string& response) override;
    public:
        int version_;
        int subversion_;
        std::string versionName_;
        std::string downloadUrl_;
        std::string description_;
    };
    // 发送短信验证码请求应答
    class SendCaptchaRequest : public RequestBase {
    public:
        SendCaptchaRequest(std::string type, std::string mobile, std::string pre);
    protected:
        virtual std::string OnGetHost() const override;
        virtual std::string OnGetAPI() const override;
        virtual void OnGetRequestHead(std::map<std::string, std::string>& heads) const override;
        virtual void OnGetRequestContent(std::string& content) const override;
    public:
        std::string type_;
        std::string mobile_;
        std::string pre_;
    };
    class SendCaptchaResponse : public ResponseBase {
    protected:
        virtual void OnParse(const std::string& response) override;
    public:
        std::string msg_;
    };
    // 注册账号请求/应答
    class RegisterAccountRequest : public RequestBase {
    public:
        RegisterAccountRequest(std::string mobile,
                               std::string pre,
                               std::string password,
                               std::string code,
                               std::string nickname,
                               std::string deviceid);
    protected:
        virtual std::string OnGetHost() const override;
        virtual std::string OnGetAPI() const override;
        virtual void OnGetRequestHead(std::map<std::string, std::string>& heads) const override;
        virtual void OnGetRequestContent(std::string& content) const override;

    public:
        std::string mobile_;
        std::string pre_;
        std::string password_;
        std::string code_;
        std::string nickname_;
        std::string deviceid_;
    };
    class RegisterAccountResponse : public ResponseBase {
    protected:
        virtual void OnParse(const std::string& response) override;
    public:
        std::string msg_;
    };
    // 登录账号请求/应答
    class LoginAccountRequest : public RequestBase {
    public:
        LoginAccountRequest(std::string account,
                            std::string password,
                            std::string deviceid);

    protected:
        virtual std::string OnGetHost() const override;
        virtual std::string OnGetAPI() const override;
        virtual void OnGetRequestHead(std::map<std::string, std::string>& heads) const override;
        virtual void OnGetRequestContent(std::string& content) const override;

    public:
        std::string account_;
        std::string password_;
        std::string deviceid_;
    };
    class LoginAccountResponse : public ResponseBase {
    protected:
        virtual void OnParse(const std::string& response) override;

    public:
        std::string msg_;
        std::string accid_;
        std::string token_;
        std::string yxToken_;
        std::string avatar_;
        std::string nickname_;
        int user_id_;
    };
    // 获取用户信息请求/应答
    class GetUserInfoRequest : public RequestBase {
    public:
        GetUserInfoRequest(std::string token);

    protected:
        virtual std::string OnGetHost() const override;
        virtual std::string OnGetAPI() const override;
        virtual void OnGetRequestHead(std::map<std::string, std::string>& heads) const override;
        virtual void OnGetRequestContent(std::string& content) const override;

    public:
        std::string token_;
    };
    class GetUserInfoResponse : public ResponseBase {
    protected:
        virtual void OnParse(const std::string& response) override;

    public:
        std::string account_;
        std::string username_;
        std::string pre_;
        std::string mobile_;
        std::string nickname_;
        std::string gode_;
        std::string baye_;
    };
    // 修改用户信息请求/应答
    class UserEditRequest : public RequestBase {
    public:
        UserEditRequest(std::string token,
            std::string signature,
            std::string nickname,
            std::string avatar);
    protected:
        virtual std::string OnGetHost() const override;
        virtual std::string OnGetAPI() const override;
        virtual void OnGetRequestHead(std::map<std::string, std::string>& heads) const override;
        virtual void OnGetRequestContent(std::string& content) const override;

    public:
        std::string token_;
        std::string signature_;
        std::string nickname_;
        std::string avatar_;
    };
    class UserEditResponse : public ResponseBase {
    protected:
        virtual void OnParse(const std::string& response) override;
    public:
        std::string msg_;
    };
    // 领取红包请求/应答
    class ReceiveRedPacketRequest : public RequestBase {
    public:
        ReceiveRedPacketRequest(std::string token, std::string pack_id, std::string tid);

    protected:
        virtual std::string OnGetHost() const override;
        virtual std::string OnGetAPI() const override;
        virtual void OnGetRequestHead(std::map<std::string, std::string>& heads) const override;
        virtual void OnGetRequestContent(std::string& content) const override;

    public:
        std::string token_;
        std::string pack_id_;
        std::string tid_;
        int type_;
    };
    class ReceiveRedPacketResponse : public ResponseBase {
    protected:
        virtual void OnParse(const std::string& response) override;

    public:
        std::string msg_;
        std::string amount_type_;
        std::string amount_;
    };
    // 查询ACCID请求/应答
    class QueryAccidRequest : public RequestBase {
    public:
        QueryAccidRequest(std::string token, std::string keyword);

    protected:
        virtual std::string OnGetHost() const override;
        virtual std::string OnGetAPI() const override;
        virtual void OnGetRequestHead(std::map<std::string, std::string>& heads) const override;
        virtual void OnGetRequestContent(std::string& content) const override;

    public:
        std::string token_;
        std::string keyword_;
    };
    class QueryAccidResponse : public ResponseBase {
    protected:
        virtual void OnParse(const std::string& response) override;

    public:
        std::string msg_;
        std::string accid_;
    };
    // 获取聊天室列表请求/应答
    class GetChatroomListRequest : public RequestBase {
    protected:
        virtual std::string OnGetAPIURL() const;
        virtual std::string OnGetAPI() const override;
        virtual bool IsUsePostMethod() const override;
    };
    class GetChatroomListResponse : public ResponseBase {
    protected:
        virtual void OnParse(const std::string& response) override;

    public:
        std::vector<nim_chatroom::ChatRoomInfo> chatroom_list_;
    };
    // 获取聊天室连接地址请求/应答
    class GetChatroomAddressRequest : public RequestBase {
    public:
        GetChatroomAddressRequest();

    protected:
        virtual std::string OnGetAPIURL() const;
        virtual std::string OnGetAPI() const override;
        virtual void OnGetRequestContent(std::string& content) const override;

    public:
        __int64 room_id_;
        std::string uid_;
        int type_;
    };
    class GetChatroomAddressResponse : public ResponseBase {
    protected:
        virtual void OnParse(const std::string& response) override;

    public:
        std::list<std::string> address_; /**< 聊天室地址，地址通过应用服务器接口获取 */
    };

public:
    /****************************对外暴露定义*****************************/
    // APP更新请求/应答
    using AppUpdateReq = TSharedHttpRequest<AppUpdateRequest>;
    using AppUpdateRsp = TSharedHttpResponse<AppUpdateResponse>;
    // 发送短信验证码请求/应答
    using SendCodeReq = TSharedHttpRequest<SendCaptchaRequest>;
    using SendCodeRsp = TSharedHttpResponse<SendCaptchaResponse>;
    // 注册账号请求/应答
    using RegisterReq = TSharedHttpRequest<RegisterAccountRequest>;
    using RegisterRsp = TSharedHttpResponse<RegisterAccountResponse>;
    // 登录请求/应答
    using LoginReq = TSharedHttpRequest<LoginAccountRequest>;
    using LoginRsp = TSharedHttpResponse<LoginAccountResponse>;
    // 获取用户信息请求/应答
    using UserInfoReq = TSharedHttpRequest<GetUserInfoRequest>;
    using UserInfoRsp = TSharedHttpResponse<GetUserInfoResponse>;
    // 修改用户信息请求/应答
    using UserEditReq = TSharedHttpRequest<UserEditRequest>;
    using UserEditRsp = TSharedHttpResponse<UserEditResponse>;
    // 领取红包请求/应答
    using RecvRedPacketReq = TSharedHttpRequest<ReceiveRedPacketRequest>;
    using RecvRedPacketRsp = TSharedHttpResponse<ReceiveRedPacketResponse>;
    // 查询ACCID请求/应答
    using QueryAccidReq = TSharedHttpRequest<QueryAccidRequest>;
    using QueryAccidRsp = TSharedHttpResponse<QueryAccidResponse>;
    // 获取聊天室列表请求/应答
    using GetChatroomListReq = TSharedHttpRequest<GetChatroomListRequest>;
    using GetChatroomListRsp = TSharedHttpResponse<GetChatroomListResponse>;
    // 获取聊天室列表请求/应答
    using GetChatroomAddressReq = TSharedHttpRequest<GetChatroomAddressRequest>;
    using GetChatroomAddressRsp = TSharedHttpResponse<GetChatroomAddressResponse>;
};
}  // namespace app_sdk
using app_sdk_pro = app_sdk::SDK_PRO;